<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>pictureManger</title>
    <link href="${pageContext.request.contextPath}/css/base.css" type="text/css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/tab.css" type="text/css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/item.css" type="text/css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/item_do.css" type="text/css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/uploadify.css" type="text/css"></link>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.uploadify.v2.0.3.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/swfobject.js"></script>
<body style="margin:1px;" id="ff">
<table id="dg" title="活动管理" class="easyui-datagrid" pagination="true"
       rownumbers="false" fit="true" data-options="pageSize:10"
       url="${pageContext.request.contextPath}/activity/search"
       toolbar="#tb" style="overflow-x: scroll;">
    <thead data-options="frozen:false">
    <tr>
        <th field="cb" checkbox="true" align="center"></th>
        <th field="id" width="100" align="center">编号</th>
        <th field="type" width="150" align="center">活动类型</th>
        <th field="actName" width="150" align="center">活动名称</th>
        <th field="introduction" width="300" align="center">活动简介</th>
        <th field="acttime" width="150" align="center">活动时间</th>
        <th field="address" width="150" align="center">活动地点</th>
        <th field="org" width="150" align="center">组织机构</th>
        <th field="scale" width="150" align="center">参与规模</th>
    </tr>
    </thead>
</table>
<div id="tb">
    <div>
        <a href="javascript:openActAddDialog()" class="easyui-linkbutton"
           iconCls="icon-add" plain="true">添加</a> <a
            href="javascript:openPictureModifyDialog()"
            class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a> <a
            href="javascript:deleteAct()" class="easyui-linkbutton"
            iconCls="icon-remove" plain="true">删除</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog"
     style="width: 800px;height:550px;padding: 10px 20px; position: relative; z-index:1000;"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" enctype="multipart/form-data">
        <div style="padding-top:10px;  float:left; width:95%; padding-left:30px;">
            <div id="i_do_wrap">
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">活动名称</p>
                    <input type="text" id="type" name="type" class="easyui-validatebox" required="true"
                           style="border:1px #9c9c9c solid;height:25px;"/>
                </div>
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">活动类型</p>
                    <input type="text" id="actName" name="actName" class="easyui-validatebox" required="true"
                           style="border:1px #9c9c9c solid;height:25px;"/>
                </div>
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">活动简介</p>
                    <textarea style="font-size: 16px" rows="15" cols="50" id="introduction" name="introduction"></textarea>
                </div>
                <div class="i_do_div rel" id="">
                    <p class="i_do_tle r_txt abs font14">活动时间</p>
                    <input id="acttime" class="easyui-datetimebox" name="acttime"
                        data-options="required:true,showSeconds:false,editable:false" style="width:150px"/>
                    <input id="id" name="id" type="hidden" value="0"/>
                </div>
                <div class="i_do_div rel" id="">
                    <p class="i_do_tle r_txt abs font14">活动地点</p>
                    <textarea style="font-size: 16px" rows="5" cols="30" id="address" name="address" required="true"></textarea>
                </div>
                 <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">组织机构</p>
                    <input type="text" id="org" name="org" class="easyui-validatebox" required="true"
                           style="border:1px #9c9c9c solid;height:25px;"/>
                </div>
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">参与规模</p>
                    <input type="text" id="scale" name="scale" class="easyui-validatebox" required="true"
                           style="border:1px #9c9c9c solid;height:25px;"/>
                </div>
            </div>
        </div>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:saveAct()" class="easyui-linkbutton"
       iconCls="icon-ok">保存</a> <a href="javascript:closePictureDialog()"
                                   class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>


</body>
<script type="text/javascript">
    var url = "${pageContext.request.contextPath}/product";
    var method;

    function searchPicture() {
        $("#dg").datagrid('load', {
            "url": $("#url").val(),
        });
    }

    function deleteAct() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要删除的数据！");
            return;
        }
        var strIds = [];
        for (var i = 0; i < selectedRows.length; i++) {
            strIds.push(selectedRows[i].id);
        }
        var ids = strIds.join(",");
        $.messager.confirm("系统提示", "您确认要删除这<font color=red>"
                + selectedRows.length + "</font>条数据吗？", function (r) {
            if (r) {
                $.ajax({
                    type: "GET",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/activity/delete/" + ids,//url
                    data: {},
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                           
                            $("#dg").datagrid(
                                    "reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "数据删除失败！");
                        }

                        ;
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });

    }
    
    function openActAddDialog() {
        $("#dlg").dialog("open").dialog("setTitle", "添加活动");
        method = "POST";
        url="/activity/insert";
    }


    function saveAct() {
    	var actName=$("#actName").val();
        var type=$("#type").val();
    	var acttime=$("#acttime").datetimebox("getValue");
        var id = $("#id").val();
        var introduction = $("#introduction").val();
        var address = $("#address").val();
        var org = $("#org").val();
        var scale = $("#scale").val();
        var data = {"id": id, "actName":actName,"acttime": acttime,"type":type, "introduction": introduction,"address":address,"org":org,"scale":scale};
        $.ajax({
            type: method,
            dataType: "json",
            url: url,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(data),
            success: function (result) {
                console.log(result);//打印服务端返回的数据
                if (result.resultCode == 200) {
                    $.messager.alert("系统提示", "保存成功");
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                    resetValue();
                }
                else {
                    $.messager.alert("系统提示", "操作失败");
                    $("#dlg").dialog("close");
                    resetValue();
                }
            },
            error: function () {
                $.messager.alert("系统提示", "操作失败");
            }
        });
    }

    function openPictureModifyDialog() {
        var selectedRows = $("#dg").datagrid('getSelections');
        var row = selectedRows[0];
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要编辑的数据！");
            return;
        }
        $("#dlg").dialog("open").dialog("setTitle", "活动修改");
        $('#fm').form('load', row);
        $("#id").val(row.id);
        method = "POST";
        url="/activity/update";
    }


    function resetValue() {
    	$("#type").val('');
        $("#acttime").val('');
        $("#id").val('');
        $("#introduction").val('');
        $("#address").val('');
        $("#org").val('');
        $("#scale").val('');
        $("#actName").val('');
    }

    function closePictureDialog() {
        $("#dlg").dialog("close");
        resetValue();
    }
</script>
</head>

</html>